<?php
	function db_insert_feed_back($_POST)
	{
		global $wpdb;
		$error = null;
		if(isset($_POST['send-feed-back']))
		{
			if($_SESSION['ma_xac_nhan']!= $_POST['Security'])
			{
				$error .= "The code Security invalid! Please try again.";
			}
			else 
			{	
				## luu bai post feed back	
				$mypost = array(
					'post_title' 	=> $_POST['Name'],
					'post_type' 	=> 'testimonial',	
				    'post_content'  => $_POST['Comment'],
				    'post_status' 	=> 'publish',
				    'post_author' 	=> 1	    
				);	
				$postID = wp_insert_post($mypost);
				
				## update customfied
				update_post_meta($postID,$wpdb->prefix.'feed_back_address',$_POST['Address']);
				update_post_meta($postID,$wpdb->prefix.'feed_back_email',$_POST['Email']);
				update_post_meta($postID,$wpdb->prefix.'feed_back_phone',$_POST['Tel']);
				## upload hinh anh bai feed back
				$str_image = null;
				if($_FILES['files']['size']>0)
				{
					foreach ($_FILES['files']['name'] as $value) 
					{
						$str_image.=$value.',';
					}
				} 
				if($_FILES['file_photo']['size']>0)
				{
					update_post_meta($postID,$wpdb->prefix.'thumbnail',$_FILES['file_photo']['name']);
				}
				update_post_meta($postID,$wpdb->prefix.'feed_back_list_image',$str_image);
			}
			return $error;
		}
	}
	
?>
<div>
	<form action="" method="post" enctype="multipart/form-data">
		Ten:
		<input type="text" name="Name" value=""> <br/>
		Dia Chi
		<input type="text" name="Address" value=""> <br/>
		Email
		<input type="text" name="Email" value=""> <br/>
		Dien thoai
		<input type="text" name="Tel" value=""> <br/>
		noi dung
		<textarea rows="5" cols="50" name="Comment"></textarea><br/>
		
		<input type="file" size="10" name="file_photo" value="Browse.." /><br/>
		Addmore Images
		  <input type="file" name="files[]" multiple> <br/>
		Scurity
		<input type="text" name="Security" value=""> <br/>		
		<input type="submit" name="send-feed-back" value="Send">
	</form>
</div>
